<%@page import="com.crossriver.crgis.database.service.Held_PlotsLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQuery"%>
<%@page import="com.crossriver.crgis.database.model.Held_Plots"%>
<%@page import="com.crossriver.crgis.database.model.impl.Property_InformationImpl"%>
<%@page import="com.crossriver.crgis.database.model.impl.Contact_InformationImpl"%>
<%@page import="com.crossriver.crgis.database.model.impl.Individual_InformationImpl"%>
<%@page import="com.crossriver.crgis.database.service.persistence.Application_C_of_OUtil"%>
<%@page import="com.crossriver.crgis.database.model.Supporting_Document"%>
<%@page import="com.crossriver.crgis.database.model.Property_Information"%>
<%@page import="com.crossriver.crgis.database.model.Contact_Information"%>
<%@page import="com.crossriver.crgis.database.model.History_Of_Information"%>
<%@page import="com.crossriver.crgis.database.model.Individual_Information"%>
<%@page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.crossriver.crgis.database.model.Application_C_of_O"%>
<%@page import="com.crossriver.crgis.database.service.Application_C_of_OLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.LayoutLocalServiceUtil"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ include file="/init.jsp"%>


<%

Application_C_of_O appl =
		(Application_C_of_O)request.getAttribute(
				ApplicationCofOConstants.APPL_C_OF_O_SESSION_ATTR);


Individual_Information indInfo = (Individual_Information)
			request.getAttribute(
				ApplicationCofOConstants.INDIVIDUAL_INFO_SESSION_ATTR);

if(null == indInfo){
	indInfo = 	new Individual_InformationImpl();
}

List<History_Of_Information> history = (List<History_Of_Information>)
					request.getAttribute(
						ApplicationCofOConstants.HISTORY_INFO_SESSION_ATTR);

if(null == history){
	history = new ArrayList<History_Of_Information>();
}

Contact_Information indContInfo = (Contact_Information)
		request.getAttribute(
			ApplicationCofOConstants.IND_CONTACT_SESSION_ATTR);

if(null == indContInfo){
	indContInfo = new Contact_InformationImpl();
}

Property_Information propInfo = (Property_Information)
			request.getAttribute(
				ApplicationCofOConstants.PROPERTY_INFO_SESSION_ATTR);

if(null == propInfo){
	propInfo = new Property_InformationImpl();
}


List<Supporting_Document> suppDocs = (List<Supporting_Document>)
			request.getAttribute(
				ApplicationCofOConstants.SUPP_DOC_INFO_SESSION_ATTR);

if (null == suppDocs){
	suppDocs = new ArrayList<Supporting_Document>();
}
int heldPlotsCounter =0;
List<Held_Plots> heldPlots = null;

//heldPlots = ApplicationActionUtil.getHeldPlots(actionRequest);
DynamicQuery query = DynamicQueryFactoryUtil.forClass(Held_Plots.class)
.add(PropertyFactoryUtil.forName("applicationId").eq(new String(appl.getApplicationId())));

try {
	 heldPlots=	Held_PlotsLocalServiceUtil.dynamicQuery(query);
	 heldPlotsCounter = heldPlots.size();
} catch (SystemException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
%>


<liferay-ui:error key="functionality-under-development" message="functionality-under-development" />

<div id="main">
	<h1>Online Application Details</h1>
	<div class="content">
	
		<div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<%
				if("re-certification".equalsIgnoreCase(appl.getApplication())){
				%>	
				<li class="ui-state-default ui-corner-top"><a href="#tabs-FI">File Information</a></li>
				<%
				}
				%>
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-AI">Application Information</a></li>
				<li class="ui-state-default ui-corner-top"><a href="#tabs-PI">Personal Information</a></li>
				<li class="ui-state-default ui-corner-top"><a href="#tabs-CI">Contact Information</a></li>
				<li class="ui-state-default ui-corner-top"><a href="#tabs-HoA">History of Application</a></li>
				<li class="ui-state-default ui-corner-top"><a href="#tabs-PIN">Property Information</a></li>
				<li class="ui-state-default ui-corner-top"><a href="#tabs-SD">Supporting Documents</a></li>
			</ul>
	
			<!-- Show this if it is Re-CofO -->
			<%
			if("re-certification".equalsIgnoreCase(appl.getApplication())){
			%>
			<div id="tabs-FI" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
				<p>
					<table>
						<tr>
							<td colspan="4">
								<span class="dtitle">Old Certificate of Occupancy Number</span> 
								<span class="data"><%= appl.getOldCofONo()%></span>
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<span class="dtitle">File Number</span> 
								<span class="data"><%= appl.getFileNo()%></span>
							</td>
						</tr>
					</table>
				</p>
			</div>
			<%
			}
			%>
			<div id="tabs-AI" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
				<table id="botb">
					<tr>
						<td class="title-botb">
							Reference Number
						</td> 
						<td>
							<%= appl.getReferenceNo()%>
						</td>
					</tr>
					<tr>
						<td class="title-botb">
							Application Identification Number
						</td> 
						<td>
							<%= appl.getApplicationId()%>
						</td>
					</tr>
					<tr>
						<td class="title-botb">Application Status</td> 
						<td><%= appl.getStatus()%></td>
					</tr>
					
				</table>
			</div>
		
							<liferay-portlet:actionURL var="editPersonalInformation">
							  <liferay-portlet:param name="javax.portlet.action" value="editPersonalInformation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
							</liferay-portlet:actionURL>
							
			<div id="tabs-PI" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
				<table id="botb" width="100%">
					<tr>
						<td class="title-botb">Applicant's Full Name</td>
						<td colspan="5"><%= indInfo.getLastName().toUpperCase() %>, <%= indInfo.getFirstName() %> <%= indInfo.getMiddleName() %></td>
					</tr>
						
					<tr>
						<td class="title-botb" width="16%">Sex</td>
						<td width="16%"><%= indInfo.getGender() %></td>
						<td class="title-botb" width="16%">Date Of Birth</td> 
						<td width="16%"><%= indInfo.getDateOfBirth() %></td>
						<td class="title-botb" width="16%">Occupation</td> 
						<td width="20%"><%= indInfo.getOccupation() %></td>
					</tr>
					
					<tr>
						<td class="title-botb">Marital Status</td>
						<td><%= indInfo.getMaritalStatus() %></td>
						<td class="title-botb">Religion</td> 
						<td><%= indInfo.getReligion() %></td>
						<td class="title-botb"">Education</td> 
						<td><%= indInfo.getEducation() %></td>
					</tr>
					
					<tr>
						<td class="title-botb">No. Of Children</td>
						<td><%= indInfo.getNoOfChildren() %></td>
						<td class="title-botb">Nationality</td> 
						<td><%= indInfo.getNationality() %></td>
						<td class="title-botb"">LGA</td> 
						<td><%= indInfo.getLga()%></td>
					</tr>
					
					<tr>
						<td class="title-botb">State Of Origin</td>
						<td colspan="5"><%= indInfo.getStateOfOrigin() %></td>
					</tr>
				
				</table>
			</div>
			
			<div id="tabs-CI" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
				<table id="botb" width="100%">
					<tr>
						<td class="title-botb">Contact Address</td>
						<td colspan="5"><%= indContInfo.getHouseNo() %>, <%= indContInfo.getAddressLine1() %><br><%= indContInfo.getAddressLine2() %></td>
					</tr>
						
					<tr>
						<td class="title-botb" width="16%">City/Town</td>
						<td width="16%"><%= indContInfo.getCity()%></td>
						<td class="title-botb" width="16%">State</td> 
						<td width="16%"><%= indContInfo.getState() %></td>
						<td class="title-botb" width="16%">Country</td> 
						<td width="20%"><%= indContInfo.getCountry() %></td>
					</tr>
					
					<tr>
						<td class="title-botb">P.M.B Address</td>
						<td colspan="5"><%= indContInfo.getPoBox() %></td>
					</tr>
					
					<tr>
						<td class="title-botb">Mobile Phone</td>
						<td><%= indContInfo.getPhoneMobile() %></td>
						<td class="title-botb">Office Phone</td> 
						<td><%= indContInfo.getPhoneOffice() %></td>
						<td class="title-botb"">Home Phone</td> 
						<td><%= indContInfo.getPhoneHome() %></td>
					</tr>
					
					<tr>
						<td class="title-botb">Email Address</td>
						<td colspan="5"><%= indContInfo.getEmailAddress() %></td>
					</tr>
				</table>
			</div>
			
			<div id="tabs-HoA" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
				<table id="botb" width="100%">
					<tr>
						<td class="title-botb" width="32%">Application Number of Previous Application</td>
								<%
								for (int i =0; i<history.size(); i++){
									History_Of_Information hist  = history.get(i);
								%>
						<td width="68%"><%= hist.getOldApplicationId()%></td>
								<%
								}
								%>
					</tr>
				</table>
			</div>

			<div id="tabs-PIN" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
				<table id="botb" width="100%">
					<%
					if("stateland".equalsIgnoreCase(appl.getApplication())){
					%>
					<tr>
						<td class="title-botb">Plot Location</td>
						<td colspan="5"><%= propInfo.getLocationType() %></td>
					</tr>
					<%
					if ("town".equalsIgnoreCase(propInfo.getLocationType())){
					%>
					<tr>
						<td class="title-botb" width="16%">LGA</td>
						<td width="16%"><%= propInfo.getLga() %></td>
						<td class="title-botb" width="16%">Town</td> 
						<td width="16%"><%= propInfo.getTown()%></td>
						<td class="title-botb" width="16%">Village</td> 
						<td width="20%"><%= propInfo.getVillage()%></td>
					</tr>
					<%
					}else
					{
					%>
					<tr>
						<td class="title-botb">Plot Layout</td>
						<td colspan="5"><%= propInfo.getLandLocation() %></td>
					</tr>
					<%
					}
					%>
					
					<tr>
						<td class="title-botb">Full description of plot</td>
						<td colspan="5"><%= propInfo.getOtherUsefulInformation()%></td>
					</tr>
					
					<tr>
						<td class="title-botb" width="16%">Length of term applied for</td>
						<td width="16%"><%= propInfo.getTerm() %></td>
						<td class="title-botb" width="16%">Estimated Cost of Development</td> 
						<td width="16%">&#8358;<%= propInfo.getEstDevCost()%></td>
						<td class="title-botb" width="16%">Time to start building</td> 
						<td width="20%"><%= propInfo.getEstStartDate() %></td>
					</tr>
					
					<tr>
						<td colspan="5">
						<strong>Particulars of Plots held by applicant:</strong>
						<table border="thin solid #CCCCCC" cellpadding="0" cellspacing="0" id="tblparticulars">
							<tr>
								<td>Location</td>
								<td>Area(sq.m.)</td>
								<td>Is Plot Developed?</td>
								<td>Mode of Acquisition</td>
								<td>Registration Particulars</td>
							</tr>
								<%
								for (int i = 0; i <heldPlotsCounter; i++) {
									Held_Plots held_plotItem = heldPlots.get(i);
								%>
							<tr id="<%= i %>">
								<td><%= held_plotItem.getLocation() %> </td>
							 	<td><%= held_plotItem.getArea() %></td>
							 	<td><%= held_plotItem.getDeveloped()%></td>
							 	<td><%=held_plotItem.getAcquisitionMode() %></td>
							 	<td><%= held_plotItem.getRegParticulars() %></td>
							</tr>
								<%
								}
								%>
							
						</table>
						</td>
					</tr>
				
					<tr>
						<td class="title-botb" width="16%">Land Use</td>
						<td width="16%"><%= appl.getLandUseType() %></td>
						<td class="title-botb" width="16%">Land Purpose</td> 
						<td colspan="3"><%= appl.getLandUsePurpose()%></td>
					</tr>
					
					<%	
					}else{
					%>
						
					<tr>
						<td class="title-botb">Land Use</td>
						<td><%= appl.getLandUseType() %></td>
						<td class="title-botb">Land Purpose</td> 
						<td colspan="3"><%= appl.getLandUsePurpose()%></td>
					</tr>
					
					<tr>
						<td class="title-botb" width="16%">Property Type</td>
						<td width="16%"><%= propInfo.getPropertyType()%></td>
						<td class="title-botb" width="16%">Land Area</td> 
						<td width="16%"><%= propInfo.getArea()%> <%= propInfo.getUom()%></td>
						<td class="title-botb"" width="16%">Block No.</td> 
						<td width="20%"><%= propInfo.getBlockNo()%></td>
					</tr>
					
					<tr>
						<td class="title-botb">Land Location</td>
						<td><%= propInfo.getLandLocation()%></td>
						<td class="title-botb">City/Town/Village</td> 
						<td colspan="3"><%= propInfo.getCity()%>, <%= propInfo.getState()%>, <%= propInfo.getCountry()%></td>
					</tr>
					
					<tr>
						<td class="title-botb">Additional useful information</td>
						<td colspan="5"><%= propInfo.getOtherUsefulInformation()%></td>
					</tr>
					
					<tr>
						<td class="title-botb">Date on the Original Certifiate of Occupancy (CofO)</td>
						<td><%= propInfo.getOrigCofODate()%></td>
						<td class="title-botb">Was original allocation made to applicant?</td>
						<td><%= propInfo.getAllocationMadToYou()%></td>
						<td class="title-botb">Does applicant have an assignment?</td>
						<td><%= propInfo.getAssignedToYou()%></td>
					</tr>
					
					<%
					}
					%>
				</table>
			</div>

			<div id="tabs-SD" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
				<table id="botb" width="100%">
					<tr>
						<td class="title-botb" width="32%">Document Name</td>
						<td class="title-botb" width="50%">File Name</td> 
						<td class="title-botb"" width="18%">Document Type</td> 
					</tr>
					
						<%
							for (int i = 0; i<suppDocs.size(); i++){
								Supporting_Document suppDoc = suppDocs.get(i);
						%>
					<tr>
						<td class="title-botb"><%= suppDoc.getDocumentName() %></td>
						
						<portlet:resourceURL var="supportDoc">
							<portlet:param name="documentId" value="<%=suppDoc.getDocumentId() %>" />
							<portlet:param name="downloadType" value="dynamic" />
						</portlet:resourceURL>
						
						<td>
							<%= suppDoc.getFileName() %>
							
							<%=
								"<a href='" + supportDoc+ "'>" + suppDoc.getDocumentName() + 
						    " - "  +
						    " " + suppDoc.getFileName() +" " +
						    "  </a>"  
						  %>
						</td>
						
						<td >
						<%= suppDoc.getDocumentType() %>
						</td>
										
					</tr>
						<%
						}
						%>
				</table>
			</div>
		</div>
		
<portlet:renderURL var="applicationList">
		<portlet:param name="jspPage" value="/html/bocofo/view.jsp" />
</portlet:renderURL>

<%
	long plidMgtProfile = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), true, "/friendlyappcofo").getPlid();
%>

<liferay-portlet:actionURL portletName="printcofo_WAR_CRGISTransactionCofOportlet" plid="<%= plidMgtProfile %>" var="printerFriendly" >
	<liferay-portlet:param name="javax.portlet.action" value="printerFriendly"></liferay-portlet:param>
 	<liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
</liferay-portlet:actionURL>


 <script type="text/javascript">
	// Popup window code
	function printerFriendlyPopup(url) {
		popupWindow = window.open(
			url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
	}
</script>
	

<div>

	<liferay-portlet:actionURL name="pushAppToILS" var="pushAppToILS"></liferay-portlet:actionURL>
	<br>
	<aui:form action="<%=pushAppToILS.toString() %>" method="post" name="saveAddressInformation_fm">
		<aui:input name="applicationId" type="hidden" value="<%= appl.getApplicationId() %>"></aui:input>
		<aui:button type="submit" value="Push Application to LRS" onClick="setButtonClicked('pushApplicationToLRS');" ></aui:button>
	 	<aui:button type="button" value="Request For More Information" onClick="setButtonClicked('alert(1234)');" ></aui:button> 
	 	<a href="<%=applicationList %>"><aui:button type="button" value="Applications List"/></a> 
	  <a href="JavaScript:printerFriendlyPopup('<%= printerFriendly %>');"><aui:button type="button" value="Printer Friendly"/></a>

	 </aui:form>

	<br>	
	<liferay-portlet:actionURL name="changeApplicationStatus" var="changeApplicationStatus"></liferay-portlet:actionURL>
	<div>
		<aui:form action="<%=changeApplicationStatus.toString() %>" method="post" name="changeApplicationStatus_fm" >
		<aui:select name="applStatus" inlineField="true" label="LRS Application Status ">
			<aui:option label="NEW" value="NEW"></aui:option>
			<aui:option label="SUBMITTED" value="SUBMITTED"></aui:option>
			<aui:option label="PROCESSING" value="PROCESSING"></aui:option>
			<aui:option label="APPLICATION READY" value="APPLICATION READY"></aui:option>
			<aui:option label="CANCELLED" value="CANCELLED"></aui:option>
		</aui:select>
		<aui:input name="applicationId" type="hidden" value="<%= appl.getApplicationId() %>"></aui:input>
		<aui:button type="submit" value="Change Application Status"></aui:button>
	</aui:form>
	</div>

</div>

	</div>
</div>
<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
</script>
		